package com.cxb.file;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class JsonFileReader {
    public static void main(String[] args) {
        List<JSONObject> external = new ArrayList<>();
        List<JSONObject> internal = new ArrayList<>();
        try {
            // 读取类路径下的 JSON 文件
            InputStream inputStream = JsonFileReader.class.getResourceAsStream("/eshidai.json");
            InputStreamReader reader = new InputStreamReader(inputStream);

            // 读取文件内容并解析为 JSON 对象
            int fileData;
            StringBuilder jsonBuilder = new StringBuilder();
            while ((fileData = reader.read()) != -1) {
                jsonBuilder.append((char) fileData);
            }
            String mail = jsonBuilder.toString();
            JSONArray jsonArray = JSONArray.parse(mail);
            for (Object o : jsonArray) {
                JSONObject jsonObject = (JSONObject) o;
                System.out.println(jsonObject.getString("name") + " =============== " + jsonObject.getString("contentRelId"));
            }
            // 关闭输入流
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}